//------------------------------------------------------------------------------
// The contents of this file are subject to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at  http://www.nopCommerce.com/License.aspx. 
// 
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
// See the License for the specific language governing rights and limitations under the License.
// 
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
// 
// Contributor(s): _______. 
//------------------------------------------------------------------------------

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tathata.Common;
using Tathata.Common.BLL.Entities;
using Tathata.Common.BLL.Managers;
using System.Text;
using Tathata.Common.Utils;
using Tathata.Common.BLL.EntityCollections;

namespace Tathata.Web
{
    public partial class main : BaseNopMasterPage
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (SettingManager.GetSettingValueBoolean("Common.StoreClosed"))
                Response.Redirect("~/StoreClosed.htm");

            if (!Page.IsPostBack)
            {
                CheckAffiliate();
            }

            string defaulSEOTitle = SettingManager.GetSettingValue("SEO.DefaultTitle");
            string defaulSEODescription = SettingManager.GetSettingValue("SEO.DefaultMetaDescription");
            string defaulSEOKeywords = SettingManager.GetSettingValue("SEO.DefaultMetaKeywords");
            SEOHelper.RenderTitle(this.Page, defaulSEOTitle, false);
            SEOHelper.RenderMetaTag(this.Page, "description", defaulSEODescription, false);
            SEOHelper.RenderMetaTag(this.Page, "keywords", defaulSEOKeywords, false);
        }

        private void CheckAffiliate()
        {
            int affiliateID = 0;
            Affiliate affiliate = AffiliateManager.GetByAffiliateID(CommonHelper.QueryStringInt("AffiliateID"));
            if (affiliate != null && affiliate.Active)
                affiliateID = affiliate.AffiliateID;
            if (affiliateID > 0)
            {
                HttpCookie affiliateCookie = HttpContext.Current.Request.Cookies.Get("NopCommerce.AffiliateID");
                if (affiliateCookie == null)
                    affiliateCookie = new HttpCookie("NopCommerce.AffiliateID");

                affiliateCookie.Value = affiliateID.ToString();
                affiliateCookie.Expires = DateTime.Now.AddDays(1.0);
                HttpContext.Current.Response.Cookies.Set(affiliateCookie);
            }
        }
    }
}
